//
//  tinyFrameModel.m
//  TinyFortune
//
//  Created by lc on 16/5/22.
//  Copyright © 2016年 lc. All rights reserved.
//

#import "tinyFrameModel.h"
#import "tinyDataModel.h"
@implementation tinyFrameModel

- (void)setDataModel:(tinyDataModel *)dataModel{
    _dataModel = dataModel ;
    _time = _dataModel.time;
    //==========计算子视图的frame========
    //cell的宽和高
    CGFloat cellW = LC_WIDTH ;
    CGFloat margin = 10 ;
    //头像
    CGFloat iconX = margin *2;
    CGFloat iconY = margin ;
    CGFloat iconW = 50 ;
    CGFloat iconH = iconW ;
    _iconFrame = CGRectMake(iconX, iconY, iconW, iconH);
    //名字
    //计算文字的宽度和高度
    CGRect nameRect = [dataModel.name boundingRectWithSize:CGSizeMake(cellW - 2 *margin - iconW, 100.0f) options:NSStringDrawingUsesLineFragmentOrigin  attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17]} context:nil];
    CGFloat nameX = iconW + iconX + 2*margin ;
    CGFloat nameY = iconY * 1.5 ;
    CGFloat nameW = nameRect.size.width;
    CGFloat nameH = nameRect.size.height;
    _nameFrame = CGRectMake(nameX, nameY, nameW, nameH);
   
    //时间
    CGRect timeRect = [dataModel.time boundingRectWithSize:CGSizeMake(cellW - margin *2 - iconW, 100) options:NSStringDrawingUsesLineFragmentOrigin   attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:11]} context:nil];
    CGFloat timeX = cellW - 2 * margin - timeRect.size.width ;
//    CGFloat timeY = nameY ;
//    _timeFrame = CGRectMake(timeX, timeY, timeRect.size.width, timeRect.size.height);
    //图片
    CGFloat photoX = margin   ;
    CGFloat photoY = iconY +iconH + 1 -margin *1.5 ;
    CGFloat photoW = LC_WIDTH - 2 * margin;
    CGFloat photoH = 320 ;
    _photoFrame = CGRectMake(photoX, photoY, photoW, photoH);
    //内容
    CGFloat textX = margin/2.0f ;
    CGFloat textY = margin + photoH + photoY;
    CGRect textRect = [dataModel.text boundingRectWithSize:CGSizeMake(cellW - 2 * margin, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin   attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil];
    _textFrame = CGRectMake(textX, textY, textRect.size.width, textRect.size.height);
   
    
        //点赞
    CGFloat favouriteX = margin ;
    CGFloat favouriteY = textY + textRect.size.height + margin *2;
    CGFloat favouriteW = 80 ;
    CGFloat favouriteH = 20 ;
    _favouriteFrame = CGRectMake(favouriteX, favouriteY, favouriteW, favouriteH);
    //评论
    CGFloat commendX = margin *2.0 + favouriteW;
    CGFloat commendY = textY + textRect.size.height + margin*2;
    CGFloat commendW = 80 ;
    CGFloat commendH = 20 ;
    _commendFrame = CGRectMake(commendX, commendY, commendW, commendH);
    
    
    CGFloat timeY = commendY;
    _timeFrame = CGRectMake(timeX, timeY, timeRect.size.width, timeRect.size.height);
    
    
    //cell的高度
    _cellHeight = commendH + commendY + margin;
    
}

@end
